home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_client_search.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  11.3 KB  |  558 lines

  1. unit ntc_client_search;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Variants,
  30.     Classes,
  31.     Graphics,
  32.     Controls,
  33.     Forms,
  34.     Dialogs,
  35.     ExtCtrls,
  36.     StdCtrls,
  37.     Buttons,
  38.     inifiles,
  39.  
  40.     ntc_client_object,
  41.     ntc_client_form;
  42.  
  43. const
  44.     seconds_in=60*60;
  45.     seconds_in_az=360*seconds_in;
  46.     seconds_in_alt=360*seconds_in;
  47.     degrees_in_quarter=90;
  48.     percent_100=65535;
  49.     { correcting }
  50.     default_intercept=99.834586;
  51.     default_co_efficient_1=0.043221;
  52.     default_co_efficient_2=-0.017952;
  53.     default_co_efficient_3=5.71035432E-05;
  54.     default_height=240;
  55.     default_width=320;
  56.     default_height_part=20;
  57.     default_width_part=20;
  58.     default_seconds=1;
  59.     default_timeout=2000;
  60.  
  61. type
  62.     button_type_set=(
  63.         b_west,
  64.         b_east,
  65.         b_north,
  66.         b_south);
  67.     button_type=set of button_type_set;
  68.  
  69.     Tscope_search = class(TForm)
  70.         search_panel: TPanel;
  71.         dimensions_group: TGroupBox;
  72.         cycler_group: TGroupBox;
  73.         timeout_edit: TEdit;
  74.         timeout_label: TLabel;
  75.         out_panel: TPanel;
  76.         search_timer: TTimer;
  77.         out_label: TLabel;
  78.         in_panel: TPanel;
  79.         in_label: TLabel;
  80.         clock_panel: TPanel;
  81.         clock_label: TLabel;
  82.         counter_panel: TPanel;
  83.         counter_label: TLabel;
  84.         out_button: TSpeedButton;
  85.         in_button: TSpeedButton;
  86.         clock_button: TSpeedButton;
  87.         counter_button: TSpeedButton;
  88.     reset_group: TGroupBox;
  89.     stop_panel: TPanel;
  90.     stop_button: TSpeedButton;
  91.     stop_label: TLabel;
  92.     reset_panel: TPanel;
  93.     reset_label: TLabel;
  94.     reset_button: TSpeedButton;
  95.         { end test code *** }
  96.  
  97.         { form handlling }
  98.         procedure FormCreate(
  99.             Sender: TObject);
  100.  
  101.         procedure form_close_query(
  102.                     Sender: TObject;
  103.             var CanClose: Boolean);
  104.  
  105.         procedure disable_panel;
  106.         procedure enable_panel;
  107.  
  108.         { configuration }
  109.         procedure save_settings;
  110.  
  111.         procedure load_settings;
  112.  
  113.         procedure flip_buttons(
  114.             toggle:boolean);
  115.  
  116.         { slewing functions }
  117.         procedure reset;
  118.  
  119.         procedure move_screen(
  120.             t:string);
  121.  
  122.         { events }
  123.         procedure out_buttonClick(
  124.             Sender: TObject);
  125.  
  126.         procedure change_button(
  127.             button:string);
  128.  
  129.         procedure clock_buttonClick(
  130.             Sender: TObject);
  131.  
  132.         procedure counter_buttonClick(
  133.             Sender: TObject);
  134.  
  135.         procedure in_buttonClick(
  136.             Sender: TObject);
  137.  
  138.         procedure reset_buttonClick(
  139.             Sender: TObject);
  140.  
  141.         procedure stop_buttonClick(
  142.             Sender: TObject);
  143.  
  144.         procedure FormShow(
  145.             Sender:TObject);
  146.  
  147.         procedure adjust;
  148.  
  149.         procedure check_activate(
  150.             Sender: TObject);
  151.  
  152.         { timer }
  153.         procedure enable_timer;
  154.         procedure disable_timer;
  155.         procedure poll_scope;
  156.  
  157.         procedure search_timerTimer(
  158.             Sender: TObject);
  159.  
  160.         procedure timeout_editClick(
  161.             Sender: TObject);
  162.  
  163.     private
  164.         { Private declarations }
  165.         timeout_interval:integer;
  166.         dont_reset:boolean;
  167.     public
  168.         { Public declarations }
  169.         { moving }
  170.         frame_level:integer;
  171.         frame_dir:string;
  172.         { configuration }
  173.         dimensions:dimensions_record;
  174.  
  175.         { events }
  176.         procedure check_visible_and_show_hide(
  177.             sender:tobject);
  178.  
  179.         procedure hide_form;
  180.         procedure show_form;
  181.     end;
  182.  
  183. var
  184.     scope_search: Tscope_search;
  185.  
  186. implementation
  187.  
  188. uses
  189.     ntc_client_network,
  190.     ntc_client_info,
  191.     ntc_client_control;
  192.  
  193. {$R *.dfm}
  194. {$R icons.res}
  195.  
  196.     { -------------
  197.         form handling
  198.         ------------- }
  199.  
  200. procedure Tscope_search.FormCreate(
  201.     Sender: TObject);
  202. begin
  203.     search_timer.enabled:=false;
  204.     flip_buttons(false);
  205.     load_settings;
  206.     dont_reset:=false;
  207. end;
  208.  
  209. procedure tscope_search.form_close_query(
  210.             Sender: TObject;
  211.     var CanClose: Boolean);
  212. begin
  213.     canclose:=false;
  214.     visible:=false;
  215.     with dimensions do
  216.         begin
  217.             form_top:=top;
  218.             form_left:=left;
  219.         end;
  220. end;
  221.  
  222. procedure tscope_search.disable_panel;
  223. begin
  224.     flip_buttons(false);
  225.     out_button.enabled:=false;
  226.     in_button.enabled:=false;
  227.     clock_button.enabled:=false;
  228.     counter_button.enabled:=false;
  229. end;
  230.  
  231. procedure tscope_search.enable_panel;
  232. begin
  233.     flip_buttons(true);
  234.     out_button.enabled:=true;
  235.     in_button.enabled:=true;
  236.     clock_button.enabled:=true;
  237.     counter_button.enabled:=true;
  238. end;
  239.  
  240. procedure tscope_search.FormShow(
  241.     Sender:TObject);
  242. begin
  243.     with dimensions do
  244.         begin
  245.             top:=form_top;
  246.             left:=form_left;
  247.         end;
  248. end;
  249.  
  250. procedure tscope_search.adjust;
  251. begin
  252.     with dimensions do
  253.         begin
  254.             form_top:=trunc(form_top/last_screen_height*current_height);
  255.             form_left:=trunc(form_left/last_screen_width*current_width);
  256.         end;
  257.     if visible then
  258.         show;
  259. end;
  260.  
  261. procedure tscope_search.check_visible_and_show_hide(
  262.     sender:tobject);
  263. begin
  264.     if visible then
  265.         hide_form
  266.     else
  267.         show_form;
  268.     scope.show_hide(sender,visible);
  269. end;
  270.  
  271. procedure tscope_search.hide_form;
  272. begin
  273.     with dimensions do
  274.         begin
  275.             form_top:=top;
  276.             form_left:=left;
  277.         end;
  278.     Visible:=false;
  279. end;
  280.  
  281. procedure tscope_search.show_form;
  282. begin
  283.     Visible:=true;
  284. end;
  285.  
  286. procedure tscope_search.check_activate(
  287.     Sender: TObject);
  288. begin
  289.     scope.form_activate(scope_search,@dimensions);
  290. end;
  291.  
  292.     { ---------
  293.         utilities
  294.         --------- }
  295.  
  296. procedure tscope_search.flip_buttons(
  297.     toggle:boolean);
  298. begin
  299.     dimensions_group.enabled:=toggle;
  300.     cycler_group.enabled:=toggle;
  301. end;
  302.  
  303.     { -------------
  304.         configuration
  305.         ------------- }
  306.  
  307. procedure tscope_search.load_settings;
  308. begin
  309.     ini_file:=tinifile.create(application_path+'client.ini');
  310.     with ini_file do
  311.         begin
  312.             dont_reset:=true;
  313.             timeout_interval:=readinteger('search','timeout_interval',default_timeout);
  314.             timeout_edit.text:=inttostr(timeout_interval);
  315.             { form }
  316.             scope.get_dimensions(scope_search,@dimensions,'search',ini_file);
  317.             left:=dimensions.form_left;
  318.             top:=dimensions.form_top;
  319.             visible:=readbool('search','visible',false);
  320.             dont_reset:=false;
  321.         end;
  322.     ini_file.free;
  323. end;
  324.  
  325. procedure tscope_search.save_settings;
  326. begin
  327.     with ini_file do
  328.         begin
  329.             writeinteger('search','interval_timeout',timeout_interval);
  330.             { form }
  331.             scope.find_vdu(scope_search,@dimensions);
  332.             scope.write_dimensions(@dimensions,left,top,'search',ini_file);
  333.             writebool('search','visible',visible);
  334.         end;
  335. end;
  336.  
  337.     { -----------------
  338.         slewing functions
  339.         ----------------- }
  340.  
  341. procedure tscope_search.reset;
  342. begin
  343.     if scope_control.moving_scope then
  344.         disable_timer;
  345.     if scope_network.send_request_check('reset_search')>=[exit_ok] then
  346.         frame_level:=0;
  347.     enable_panel;
  348. end;
  349.  
  350.     { ----------------------------
  351.         move out to larger perimeter
  352.         ---------------------------- }
  353.  
  354. procedure Tscope_search.move_screen(
  355.     t:string);
  356. begin
  357.     if scope_network.send_request_check('move_screen_'+t)>=[exit_ok] then
  358.         enable_timer;
  359. end;
  360.  
  361. procedure Tscope_search.out_buttonClick(
  362.     Sender: TObject);
  363. var
  364.     b:string;
  365. begin
  366.     disable_panel;
  367.     with scope_network do
  368.          if not (send_request_check('break_out')=[exit_ok]) then
  369.         scope_control.write_status_log('invalid response from server')
  370.     else
  371.         begin
  372.             if scope_network.get_string('button',b) then
  373.                 change_button(b);
  374.             inc(frame_level);
  375.             enable_timer;
  376.         end;
  377. end;
  378.  
  379.     { -------------------
  380.         move to inner frame
  381.         ------------------- }
  382.  
  383. procedure Tscope_search.in_buttonClick(
  384.     Sender: TObject);
  385. begin
  386.     if frame_level>0 then
  387.          with scope_network do
  388.         begin
  389.             disable_panel;
  390.             if not (send_request_check('fall_in')=[exit_ok]) then
  391.                 scope_control.write_status_log('invalid response from server')
  392.             else
  393.                 begin
  394.                     dec(frame_level);
  395.                     enable_timer;
  396.                 end;
  397.         end;
  398. end;
  399.  
  400.     { ------------------
  401.         move to next frame
  402.         ------------------ }
  403.  
  404. procedure tscope_search.change_button(
  405.     button:string);
  406. begin
  407.     if button='north' then
  408.         begin
  409.             clock_button.glyph.LoadFromResourceName(hInstance,'NORTH_CLOCK');
  410.             counter_button.glyph.LoadFromResourceName(hInstance,'NORTH_ANTI');
  411.         end
  412.     else if button='south' then
  413.         begin
  414.             clock_button.glyph.LoadFromResourceName(hInstance,'SOUTH_CLOCK');
  415.             counter_button.glyph.LoadFromResourceName(hInstance,'SOUTH_ANTI');
  416.         end
  417.     else if button='east' then
  418.         begin
  419.             clock_button.glyph.LoadFromResourceName(hInstance,'EAST_CLOCK');
  420.             counter_button.glyph.LoadFromResourceName(hInstance,'EAST_ANTI');
  421.         end
  422.     else if button='west' then
  423.         begin
  424.             clock_button.glyph.LoadFromResourceName(hInstance,'WEST_CLOCK');
  425.             counter_button.glyph.LoadFromResourceName(hInstance,'WEST_ANTI');
  426.         end;
  427. end;
  428.  
  429. procedure Tscope_search.clock_buttonClick(
  430.     Sender: TObject);
  431. var
  432.     b:string;
  433. begin
  434.     disable_panel;
  435.     if scope_network.send_request_check('clockwise')>=[exit_ok] then
  436.         begin
  437.             enable_timer;
  438.             if scope_network.get_string('button',b) then
  439.                 change_button(b);
  440.         end
  441.     else
  442.         scope_control.write_status_log('invalid direction');
  443. end;
  444.  
  445. procedure Tscope_search.counter_buttonClick(Sender: TObject);
  446. var
  447.     b:string;
  448. begin
  449.     disable_panel;
  450.     if scope_network.send_request_check('counter')>=[exit_ok] then
  451.         begin
  452.             enable_timer;
  453.             if scope_network.get_string('button',b) then
  454.                 change_button(b);
  455.         end
  456.     else
  457.         scope_control.write_status_log('invalid direction');
  458. end;
  459.  
  460.     { -----------
  461.         reset event
  462.         ----------- }
  463.  
  464. procedure Tscope_search.reset_buttonClick(
  465.     Sender: TObject);
  466. begin
  467.     if not dont_reset then
  468.         reset;
  469. end;
  470.  
  471.     { ----------
  472.         stop event
  473.         ---------- }
  474.  
  475. procedure Tscope_search.stop_buttonClick(
  476.     Sender: TObject);
  477. begin
  478.     if not dont_reset then
  479.         reset;
  480.     scope_control.stop_scope;
  481. end;
  482.  
  483.     { -----
  484.         timer
  485.         ----- }
  486.  
  487. procedure tscope_search.enable_timer;
  488. begin
  489.     scope_control.change_panel(false);
  490.     search_timer.Interval:=timeout_interval;
  491.     search_timer.enabled:=true;
  492. end;
  493.  
  494. procedure tscope_search.disable_timer;
  495. begin
  496.     search_timer.enabled:=false;
  497.     scope_info.show_info;
  498.     scope_control.moving_scope:=false;
  499.     scope_control.change_panel(true);
  500. end;
  501.  
  502. procedure tscope_search.poll_scope;
  503. var
  504.     moving:boolean;
  505. begin
  506.     with scope_network do
  507.          if send_request_check('stopped')>=[exit_ok] then
  508.         begin
  509.             get_boolean('moving',moving);
  510.             if not moving then
  511.                 begin
  512.                     scope_control.moving_scope:=false;
  513.                     disable_timer;
  514.                 end;
  515.         end;
  516. end;
  517.  
  518. procedure Tscope_search.search_timerTimer(
  519.     Sender: TObject);
  520. begin
  521.     if not scope_network.network_timer.enabled then
  522.         poll_scope;
  523. end;
  524.  
  525. procedure overlap_change(
  526.     var s:string;
  527.     var def:double);
  528. var
  529.     d:double;
  530. begin
  531.     while (length(s)>0) and
  532.                 ((copy(s,length(s),1)>'9') or
  533.                 (copy(s,length(s),1)<'0')) do
  534.         s:=copy(s,1,length(s)-1);
  535.     if length(s)=0 then
  536.         d:=20
  537.     else
  538.         d:=strtofloatdef(s,def);
  539.     if (d>=0) and (d<100) then
  540.         def:=d
  541.     else
  542.         s:=floattostr(def);
  543.     s:=s+'%';
  544. end;
  545.  
  546. procedure Tscope_search.timeout_editClick(
  547.     Sender: TObject);
  548. begin
  549.     timeout_interval:=strtointdef(timeout_edit.text,2000);
  550.     if timeout_interval<2000 then
  551.         begin
  552.             timeout_interval:=2000;
  553.             timeout_edit.text:=inttostr(timeout_interval);
  554.         end;
  555. end;
  556.  
  557. end.
  558.